package com.regent.central.bill.web.sale_order;

import com.regent.central.bill.core.SaleOrderAction;
import com.regent.central.bill.dto.sale_order.SaleOrderActionLoggingDTO;
import com.regent.central.bill.service.SaleOrderActionLoggingService;
import com.regent.central.bill.service.SaleOrderActionService;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.annotation.Resource;
import java.util.List;

/**
 * 销售单动作变动日志管理器
 *
 * @author 杨昌沛 646742615@qq.com
 * @date 2018-07-03 11:03
 **/
@Controller
@RequestMapping("/sale-order-action-loggings")
public class SaleOrderActionLoggingController {

    @Resource
    private SaleOrderActionService saleOrderActionService;

    @Resource
    private SaleOrderActionLoggingService saleOrderActionLoggingService;

    /**
     * 获取开单货品变动日志
     *
     * @param request 开单货品变动日志请求
     * @return 开单货品变动日志结果
     */
    @RequestMapping(value = "/create-goods", method = RequestMethod.GET)
    @ResponseBody
    public SOALCreateGoodsResponse getCreateGoodsLoggings(
            SOALCreateGoodsRequest request
    ) {
        List<SaleOrderActionLoggingDTO> loggings = saleOrderActionLoggingService.getSaleOrderActionLoggings(request.getActionId());
        SOALCreateGoodsResponse response = new SOALCreateGoodsResponse();
        response.setLoggings(loggings);
        return response;
    }

    /**
     * 获取改他单/改本单货品变动日志
     *
     * @param request 改他单/改本单货品变动日志请求
     * @return 改他单/改本单货品变动日志结果
     */
    @RequestMapping(value = "/modify-goods", method = RequestMethod.GET)
    @ResponseBody
    public SOALModifyGoodsResponse getModifyGoodsLoggings(
            SOALModifyGoodsRequest request
    ) {
        String actionId = request.getActionId();
        SaleOrderAction action = saleOrderActionService.selectById(actionId);
        List<SaleOrderActionLoggingDTO> logings = saleOrderActionLoggingService.getSaleOrderActionLoggings(actionId);
        SOALModifyGoodsResponse response = new SOALModifyGoodsResponse();
        response.setSaleOrderId(action.getActionId());
        response.setLogings(logings);
        return response;
    }

    /**
     * 获取退货货品变动日志
     *
     * @param request 退货货品变动日志请求
     * @return 退货货品变动日志结果
     */
    @RequestMapping(value = "/return-goods", method = RequestMethod.GET)
    @ResponseBody
    public SOALReturnGoodsResponse getReturnGoodsLoggings(
            SOALReturnGoodsRequest request
    ) {
        List<SaleOrderActionLoggingDTO> loggings = saleOrderActionLoggingService.getSaleOrderActionLoggings(request.getActionId());
        SOALReturnGoodsResponse response = new SOALReturnGoodsResponse();
        response.setLoggings(loggings);
        return response;
    }

}
